package cn.darkhorse.device.service.impl;

import cn.darkhorse.common.constant.CommonConstant;
import cn.darkhorse.common.constant.RepairAuditStatusEnum;
import cn.darkhorse.common.constant.WebSocketEnum;
import cn.darkhorse.common.util.SysUserTranslation;
import cn.darkhorse.device.dto.MesRepairInfoDTO;
import cn.darkhorse.device.mapper.MesRepairInfoMapper;
import cn.darkhorse.device.pojo.*;
import cn.darkhorse.device.service.*;
//import cn.darkhorse.messystem.pojo.MesSystemOptions;
//import cn.darkhorse.messystem.service.MesSystemOptionsService;
import cn.darkhorse.device.vo.*;
import cn.darkhorse.messystem.pojo.MesSystemOptions;
import cn.darkhorse.messystem.service.MesSystemOptionsService;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
//import com.ruoyi.framework.websocket.WebSocketServer;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 维修单 服务实现类
 * </p>
 *
 * @author maoguanjun
 * @since 2022-11-11
 */
@Service
public class MesRepairInfoNewServiceImpl extends ServiceImpl<MesRepairInfoMapper, MesRepairInfo> implements MesRepairInfoNewService {
    @Resource
    private MesRepairInfoMapper mesRepairInfoMapper;
    @Resource
    private MesDeviceService mesDeviceService;
    @Resource
    private MesRepairApprovalHistoryService mesRepairApprovalHistoryService;
    @Resource
    private SysDeptMapper sysDeptMapper;
    @Resource
    private SysUserMapper userMapper;
    @Resource
    private ISysDictDataService dictDataService;
    @Resource
    private MesSystemOptionsService mesSystemOptionsService;
    @Resource
    private MesRepairWorkloadService mesRepairWorkloadService;
    @Resource
    private MesDeviceTypeService mesDeviceTypeService;
    @Resource
    private MesRepairCommissionInfoService mesRepairCommissionInfoService;

    /**
     * 列表
     *
     * @param mesRepairInfoDTO
     * @return
     */
    @Override
    public List<MesRepairApplyInfoVO> listAll(MesRepairInfoDTO mesRepairInfoDTO) {
        if(StringUtils.isBlank(mesRepairInfoDTO.getOrderType())){
            mesRepairInfoDTO.setOrderType(CommonConstant.ORDER_TYPE_DESC);
        }
        List<MesRepairApplyInfoVO> repairInfoVOS = mesRepairInfoMapper.listAllNew(mesRepairInfoDTO);
        if(repairInfoVOS.isEmpty()){
            return repairInfoVOS;
        }
        repairInfoVOS.forEach(item->{
            if (null!=item.getIsFixed()){

                String isFix = item.getIsFixed() == 1 ? "已修复" : "未修复";
                String disposal = "";
                if (null!=item.getDisposal() ){
                    String label = dictDataService.selectDictLabel("disposal", item.getDisposal().toString());
                    if (null!=label && !"".equals(label)){
                        disposal = "-"+label;
                    }

                }
                item.setAuditResult(isFix + disposal);
            }else {
                item.setAuditResult("--");
            }
        });
        return repairInfoVOS;
    }


    @Override
    public List<MesAllRepairInfoVO> listAllRepairInfo(MesRepairInfoDTO mesRepairInfoDTO) {
        if(StringUtils.isBlank(mesRepairInfoDTO.getOrderType())){
            mesRepairInfoDTO.setOrderType(CommonConstant.ORDER_TYPE_DESC);
        }
        return  mesRepairInfoMapper.listAllRepairInfo(mesRepairInfoDTO);
    }


    /**
     * 查看
     *
     * @param id
     * @return
     */
    @Override
    public MesRepairApplyInfoVO view(Long id) {
        MesRepairInfo info=getById(id);
        if(null==info){
            throw new ServiceException("该业务单据已删除!");
        }
        MesRepairApplyInfoVO vo=new MesRepairApplyInfoVO();
        BeanUtils.copyProperties(info,vo);
        MesDevice device=mesDeviceService.getById(info.getDeviceId());
        if(null!=device){
            vo.setPosition(device.getRegion());
        }
        if(null!=device.getType()){
            MesDeviceType type=mesDeviceTypeService.getById(device.getType());
            if(null!=type){
                vo.setDeviceTypeName(type.getTypeName());
            }
        }
        List<SysDept> sysDeptList = sysDeptMapper.selectDeptListNoAuth(new SysDept());
        Map<Long, String> deptMap = sysDeptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
        if(deptMap.containsKey(vo.getDept())){
            vo.setDeptName(deptMap.get(vo.getDept()));
        }
        LambdaQueryWrapper<MesRepairApprovalHistory> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(MesRepairApprovalHistory::getRepairId,info.getId());
        List<MesRepairApprovalHistory> list = mesRepairApprovalHistoryService.list(wrapper);
        List<SysUser> sysUsers = userMapper.selectUserListNoAuth(new SysUser());
        Map<Long, String> sysUserMap=sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId,SysUser::getNickName));

        List<MesRepairApprovalHistoryVO> dataList=new ArrayList<>();
        list.forEach(item->{
            MesRepairApprovalHistoryVO historyVO=new MesRepairApprovalHistoryVO();
            BeanUtils.copyProperties(item,historyVO);
            if(sysUserMap.containsKey(item.getApprovalPerson())){
                historyVO.setApprovalPersonName(sysUserMap.get(item.getApprovalPerson()));
            }
            dataList.add(historyVO);
        });
        if(!dataList.isEmpty()&&dataList.size()>0){
            vo.setApprovalHistories(dataList);
        }
        LambdaQueryWrapper<MesRepairWorkload> workloadWrapper=new LambdaQueryWrapper<>();
        workloadWrapper.eq(MesRepairWorkload::getRepairId,info.getId());
        List<MesRepairWorkload> workloadList = mesRepairWorkloadService.list(workloadWrapper);
        if(!workloadList.isEmpty()&&workloadList.size()>0){
            vo.setWorkloadList(workloadList);
        }
        //翻译维修人员
        SysUserTranslation st = new SysUserTranslation();
        if(StringUtils.isNotBlank(info.getRepairPersons())){
            vo.setRepairPersonsName(st.personnelTranslation(info.getRepairPersons()));
        }
        //翻译主修人
        if(null!=info.getMainRepairers()&&sysUserMap.containsKey(info.getMainRepairers())){
            vo.setMainRepairersName(sysUserMap.get(info.getMainRepairers()));
        }
        if(null!=info.getVerifier()){
            vo.setVerifierName(sysUserMap.get(info.getVerifier()));
        }
        return vo;
    }

    /**
     * 保存
     *
     * @param mesRepairInfo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveMesRepairInfo(MesRepairInfo mesRepairInfo) {
        boolean isInsert=false;
        if(null!=mesRepairInfo.getId()){
            MesRepairInfo info=getById(mesRepairInfo.getId());
            if(RepairAuditStatusEnum.TO_BE_REVIEWED.getType()!=info.getRepairStatus()){
                throw new ServiceException("只有待审核的记录可以修改！");
            }
        }else{
            isInsert=true;
        }
        if(isInsert){
            String applyCode=getApplyCode(0);
            mesRepairInfo.setApplyNum(applyCode);
            //保存创建人
            mesRepairInfo.setCreator(SecurityUtils.getUserId());
            mesRepairInfo.setGmtCraeate(LocalDateTime.now());
            //TODO 是否需要审核
            MesSystemOptions view = mesSystemOptionsService.view(null);
            if(view.getEnableRepairAudit()==1){
                mesRepairInfo.setApprovalRole(view.getRepairAuditRoles());
            }else{
                //不需要审核 保存后即为待派工
                mesRepairInfo.setAuditStatus(RepairAuditStatusEnum.TO_BE_DISPATCHED.getType());
                String repairCode=getApplyCode(1);
                mesRepairInfo.setRepairNum(repairCode);
            }
        }

        boolean b = saveOrUpdate(mesRepairInfo);
        return b;
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @Override
    public boolean delete(List<Long> ids) {
        LambdaUpdateWrapper<MesRepairInfo>wrapper=new LambdaUpdateWrapper<>();
        wrapper.in(MesRepairInfo::getId,ids);
        wrapper.set(MesRepairInfo::getDelFlag,1);
        return  update(wrapper);
    }

    /**
     * 生成报修维修单号
     *
     * @param type
     * @return
     */
    @Override
    public String getApplyCode(Integer type) {
        String code="";
        String maxCode="";
        LambdaQueryWrapper<MesRepairInfo> wrapper=new LambdaQueryWrapper<>();
        String year= String.valueOf(LocalDateTime.now().getYear());
        String month= String.valueOf(LocalDateTime.now().getMonthValue());
        String day= String.valueOf(LocalDateTime.now().getDayOfMonth());
        //报修单
        if(type==0){
            code="BX" ;
            wrapper.orderByDesc(MesRepairInfo::getApplyNum);
            wrapper.isNotNull(MesRepairInfo::getApplyNum);
            wrapper.like(MesRepairInfo::getApplyNum,code+year+month+day);
        //维修单
        }else{
            code="WX" ;
            wrapper.orderByDesc(MesRepairInfo::getRepairNum);
            wrapper.isNotNull(MesRepairInfo::getRepairNum);
            wrapper.like(MesRepairInfo::getRepairNum,code+year+month+day);
        }
        MesRepairInfo one = getOne(wrapper,false);
        Integer count=0;
        if(null!=one){
            maxCode=type==0?one.getApplyNum():one.getRepairNum();
            if (maxCode.contains("-")){
                maxCode=maxCode.substring(0,maxCode.indexOf("-"));
            }

            count=Integer.valueOf(maxCode.substring(maxCode.length()-4));
        }
        code+=year+month+day+StringUtils.padl(count + 1, 4);
        return code;
    }

    /**
     * 审核
     *
     * @param id          单据ID
     * @param approvalResult 审核结果 0立即维修1驳回
     * @param approvalOpinion 审核意见
     * @param nextUserId  下一审核人
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean approval(Long id, Integer approvalResult, String approvalOpinion, Long nextUserId,String reason) {
        MesRepairInfo info=getById(id);
        if(null==info){
            throw new ServiceException("单据不存在");
        }
        Long userId = SecurityUtils.getUserId();
        LambdaQueryWrapper<MesRepairApprovalHistory> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(MesRepairApprovalHistory::getRepairId,id);
        wrapper.eq(MesRepairApprovalHistory::getApprovalPerson,userId);
        //只查待审核
        wrapper.eq(MesRepairApprovalHistory::getApprovalResult,0);
        MesRepairApprovalHistory one = mesRepairApprovalHistoryService.getOne(wrapper, false);
        MesRepairApprovalHistory history=new MesRepairApprovalHistory();
        //存在记录，即不为首次审核人
        if(null!=one){
            history=one;
        }else{
            history.setRepairId(id);
            history.setApprovalPerson(userId);
        }
        history.setApprovalOpinion(approvalOpinion);
        history.setApprovalResult(approvalResult);
        history.setApprovalTime(LocalDateTime.now());
        boolean b = mesRepairApprovalHistoryService.saveOrUpdate(history);
        //驳回 单据作废
        if(approvalResult.equals(2)){
            info.setAuditStatus(RepairAuditStatusEnum.REJECTED.getType());
            return  updateById(info);
        }else if(approvalResult.equals(3)){
            // 转外委维修
            info.setAuditStatus(RepairAuditStatusEnum.OUTSOURCING.getType());
            info.setReason( reason);
            info.setDisposal(2);

            MesRepairCommissionInfo commissionInfo = new MesRepairCommissionInfo();
            String applyCode = mesRepairCommissionInfoService.getApplyCode();
            MesDevice byId = mesDeviceService.getById(info.getDeviceId());
            commissionInfo.setOrderNum(applyCode);
            commissionInfo.setDisposeStatus(0);
            commissionInfo.setDeviceId(info.getDeviceId());
            commissionInfo.setReason(reason);
            commissionInfo.setCreator(userId);
            commissionInfo.setGmtCreate(LocalDateTime.now());
            commissionInfo.setDeviceName(info.getDeviceName());
            commissionInfo.setDeviceCode(info.getDeviceCode());
            commissionInfo.setDeviceModel(info.getDeviceModel());
            commissionInfo.setDevicePosition(byId.getRegion());
            commissionInfo.setDeviceId(info.getDeviceId());
            commissionInfo.setDeviceType(info.getDeviceType());
            commissionInfo.setDept(byId.getDept());
            mesRepairCommissionInfoService.save(commissionInfo);
            return updateById(info);
        }
        //存在下一审核人
        if(null!=nextUserId){
            history=new MesRepairApprovalHistory();
            history.setApprovalPerson(nextUserId);
            history.setRepairId(id);
            mesRepairApprovalHistoryService.save(history);
            info.setCurrentApprover(nextUserId);
            updateById(info);
        }else{
            info.setCurrentApprover(null);
            info.setAuditStatus(RepairAuditStatusEnum.TO_BE_DISPATCHED.getType());
            info.setRepairNum(getApplyCode(1));
            updateById(info);
        }
        return b;
    }

    /**
     * 派工
     *
     * @param id
     * @param teamName      班组名称
     * @param repairPersons 维修人
     * @param mainRepairers 主修人
     * @return
     */
    @Override
    public boolean dispatch(Long id, String teamName, String repairPersons, Long mainRepairers) {
        MesRepairInfo info = getById(id);
        if(null!=info){
            info.setTeamName(teamName);
            info.setRepairPersons(repairPersons);
            info.setMainRepairers(mainRepairers);
            info.setAuditStatus(RepairAuditStatusEnum.TO_BE_REPAIRED.getType());
            return updateById(info);
        }
        return false;
    }

    /**
     * 开始维修
     *
     * @param id
     * @return
     */
    @Override
    public boolean startRepair(Long id) {
        MesRepairInfo info = getById(id);
        if(null==info){
            throw new ServiceException("单据不存在！");
        }
        if(RepairAuditStatusEnum.TO_BE_REPAIRED.getType()!=info.getAuditStatus()){
            throw new ServiceException("只有待维修的单据可以开始维修！");
        }
        info.setRepairStartTime(LocalDateTime.now());
        info.setAuditStatus(RepairAuditStatusEnum.UNDER_REPAIR.getType());
        return updateById(info);
    }

    /**
     * 结束维修
     *
     * @param id
     * @return
     */
    @Override
    public boolean endRepair(Long id) {
        MesRepairInfo info = getById(id);
        if(null==info){
            throw new ServiceException("单据不存在！");
        }
        if(RepairAuditStatusEnum.UNDER_REPAIR.getType()!=info.getAuditStatus()){
            throw new ServiceException("只有维修中的单据可以结束维修！");
        }
        info.setAuditStatus(RepairAuditStatusEnum.TO_BE_VERIFIED.getType());
        return updateById(info);
    }

    /**
     * 维修信息更新
     *
     * @param mesRepairVO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean repair(MesRepairVO mesRepairVO) {
        MesRepairInfo info = getById(mesRepairVO.getId());
        if(RepairAuditStatusEnum.UNDER_REPAIR.getType()!=info.getAuditStatus()){
            throw new ServiceException("只有维修中的单据可以更改维修信息！");
        }
        BeanUtils.copyProperties(mesRepairVO,info);
        boolean result = updateById(info);
        LambdaQueryWrapper<MesRepairWorkload> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(MesRepairWorkload::getRepairId,mesRepairVO.getId());
        mesRepairWorkloadService.remove(wrapper);
        if(null!=mesRepairVO.getWorkloadList()&&mesRepairVO.getWorkloadList().size()>0){
            mesRepairWorkloadService.saveBatch(mesRepairVO.getWorkloadList());
        }
        return result;
    }

    /**
     * 验证
     *
     * @param mesRepairVO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean verify(MesRepairVO mesRepairVO) {
        MesRepairInfo info = getById(mesRepairVO.getId());
        if(RepairAuditStatusEnum.TO_BE_VERIFIED.getType()!=info.getAuditStatus()){
            throw new ServiceException("只有待验证的单据可以验证！");
        }
        if(null==mesRepairVO.getIsFixed()){
            throw new ServiceException("是否已经修复不能为空！");
        }

        BeanUtils.copyProperties(mesRepairVO,info);

        info.setVerifier(SecurityUtils.getUserId());
        info.setAuditStatus(RepairAuditStatusEnum.DONE.getType());
        info.setVerifyTime(LocalDateTime.now());

        boolean result = updateById(info);
        LambdaQueryWrapper<MesRepairWorkload> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(MesRepairWorkload::getRepairId,mesRepairVO.getId());
        mesRepairWorkloadService.remove(wrapper);
        if(null!=mesRepairVO.getWorkloadList()&&mesRepairVO.getWorkloadList().size()>0){
            mesRepairWorkloadService.saveBatch(mesRepairVO.getWorkloadList());
        }

        if (1!=mesRepairVO.getIsFixed()){
            //   设备处置，如果选择维修，则该工单流程结束，该工单的处理状态为已完成，重新生成一个工单，新工单继续走维修流程，工单初始状态是待派工（类似于快速工单流程）；
            if (mesRepairVO.getDisposal() == 0){
                String repairNum = info.getRepairNum();
                if (repairNum.contains("-")){
                    String[] split = repairNum.split("-");
                    int i = Integer.parseInt(split[1]);
                    info.setRepairNum(split[0]+"-"+(i+1));
                }else {
                    info.setRepairNum(repairNum+"-1");
                }
                info.setVerifyTime(null);
                info.setVerifier(null);
                info.setRepairStartTime(null);
                info.setRepairEndTime(null);
                info.setId(null);
                info.setReason(null);
                info.setDisposal(null);
                info.setIsFixed(null);
                info.setRealIsStop(null);
                info.setMalfunctionReason(null);
                info.setMalfunctionType(null);
                info.setMalfunctionLevel(null);
                info.setMainRepairers(null);
                info.setTeamName(null);
                info.setRepairPersons(null);
                info.setRealTeamName(null);
                info.setRepairLevel(null);
                info.setRepairType(null);
                info.setStopHour(null);
                info.setStopMinute(null);
                info.setRepairHour(null);
                info.setRepairCost(null);
                info.setAttachments(null);
                info.setMediaAttachments(null);
                info.setRepairDescription(null);
                info.setApplyStatus(null);
                info.setGmtCraeate(LocalDateTime.now());
                quickRepair(info);
            }else if (mesRepairVO.getDisposal() == 1){
                //   设置处置，如果选择报废，则该工单流程结束；该工单的处理状态为已完成；在设备台账管理页面该设备的使用状况置为报废
                mesDeviceService.lambdaUpdate()
                        .eq(MesDevice::getId,info.getDeviceId())
                        .set(MesDevice::getUsageStatus,3).update();
            }else if (mesRepairVO.getDisposal() == 2){
                //   设备处置，如果选择外委，则生成一个外委工单，该工单流程结束；该工单的处理状态为已完成
                saveRepairCommission(info);
            }


        }
        return result;
    }

    public void saveRepairCommission(MesRepairInfo mesRepairInfo) {
        MesRepairCommissionInfoVO commissionInfo = new MesRepairCommissionInfoVO();
        commissionInfo.setDeviceId(mesRepairInfo.getDeviceId());
        commissionInfo.setDeviceCode(mesRepairInfo.getDeviceCode());
        commissionInfo.setDeviceName(mesRepairInfo.getDeviceName());
        commissionInfo.setDeviceType(mesRepairInfo.getDeviceType());
        commissionInfo.setDeviceModel(mesRepairInfo.getDeviceModel());
        MesDevice byId = mesDeviceService.getById(mesRepairInfo.getDeviceId());
//        commissionInfo.setDevicePosition(byId.getPosition());
        commissionInfo.setRepairPrincipal(mesRepairInfo.getMainRepairers().toString());
        commissionInfo.setReason(mesRepairInfo.getReason());
        commissionInfo.setDept(mesRepairInfo.getDept());

        mesRepairCommissionInfoService.saveRepairCommissionInfo(commissionInfo);
    }

    @Override
    public AjaxResult quickRepair(MesRepairInfo mesRepairInfo){
        if(null==mesRepairInfo
//                || StringUtils.isBlank(mesRepairInfo.getTeamName())||StringUtils.isBlank(mesRepairInfo.getRepairPersons())||null==mesRepairInfo.getMainRepairers()
        ){
            return AjaxResult.error("缺失参数！");
        }
        //保存创建人
        if (mesRepairInfo.getCreator() == null ){
            mesRepairInfo.setCreator(SecurityUtils.getUserId());
        }
        //不需要审核 保存后即为待派工
        mesRepairInfo.setAuditStatus(RepairAuditStatusEnum.TO_BE_DISPATCHED.getType());
        if (mesRepairInfo.getRepairNum() == null || mesRepairInfo.getRepairNum().equals("")){
            String repairCode=getApplyCode(1);
            mesRepairInfo.setRepairNum(repairCode);
        }
        mesRepairInfo.setMalfunctionSource(4);

        boolean result = save(mesRepairInfo);
        if (mesRepairInfo.getTeamName() != null && mesRepairInfo.getRepairPersons() != null && mesRepairInfo.getMainRepairers() != null){
            dispatch(mesRepairInfo.getId(),mesRepairInfo.getTeamName(),mesRepairInfo.getRepairPersons(), mesRepairInfo.getMainRepairers());

//            Long company = SecurityUtils.getLoginUser().getUser().getCompany();
//            try {
//                String[] split = mesRepairInfo.getRepairPersons().split(",");
//                if(split.length>0){
//                    JSONObject data=new JSONObject();
//                    data.put("BusinessType", WebSocketEnum.REPAIR_AUDIT_STATUS_PENDING_REPAIR.getType());
//                    data.put("BusinessTypeName", WebSocketEnum.REPAIR_AUDIT_STATUS_PENDING_REPAIR.getTypeName());
//                    data.put("BusinessStatus", WebSocketEnum.REPAIR_AUDIT_STATUS_PENDING_REPAIR.getStatus());
//                    data.put("BusinessId",mesRepairInfo.getId());
//                    for (String s : split) {
//                        WebSocketServer.sendInfo(data.toJSONString(),company+"-"+s);
//                    }
//                }
//            } catch (IOException e) {
//                throw new RuntimeException(e);
//            }
        }
        return AjaxResult.success(result);
    }

    /**
     * 获取设备状态 1 故障中 2未修复
     *
     * @return
     */
    @Override
    public Map<Integer, Set<Long>> getRepairStatusMap() {
        Map<Integer, Set<Long>> dataMap=new HashMap<>();
        //未修复
        LambdaQueryWrapper<MesRepairInfo> wrapper=new LambdaQueryWrapper<>();
        wrapper.ne(MesRepairInfo::getAuditStatus,CommonConstant.REPAIR_AUDIT_STATUS_PENDING_TRIAL);
        wrapper.ne(MesRepairInfo::getAuditStatus,CommonConstant.REPAIR_AUDIT_STATUS_OVERRULE);
        wrapper.eq(MesRepairInfo::getAuditStatus,CommonConstant.REPAIR_AUDIT_STATUS_FINISH);
        wrapper.eq(MesRepairInfo::getIsFixed,0);
        wrapper.eq(MesRepairInfo::getDelFlag,0);
        wrapper.groupBy(MesRepairInfo::getDeviceId);
        wrapper.select(MesRepairInfo::getDeviceId);
        List<Object> unRepairDevice = listObjs(wrapper);
        wrapper.clear();
        //故障维修中
        wrapper.ne(MesRepairInfo::getAuditStatus,CommonConstant.REPAIR_AUDIT_STATUS_PENDING_TRIAL);
        wrapper.ne(MesRepairInfo::getAuditStatus,CommonConstant.REPAIR_AUDIT_STATUS_OVERRULE);
        wrapper.ne(MesRepairInfo::getAuditStatus,CommonConstant.REPAIR_AUDIT_STATUS_FINISH);
        wrapper.eq(MesRepairInfo::getDelFlag,0);
        wrapper.groupBy(MesRepairInfo::getDeviceId);
        wrapper.select(MesRepairInfo::getDeviceId);
        List<Object> repairDevice = listObjs(wrapper);
        Set<Long> unRepairSet=new HashSet<>();
        Set<Long> repairSet=new HashSet<>();
        unRepairDevice.forEach(item->{
            unRepairSet.add((Long)item);
        });
        repairDevice.forEach(item->{
            if(unRepairSet.contains((Long)item)){
                unRepairSet.remove((Long)item);
            }
            repairSet.add((Long)item);
        });

        dataMap.put(1,repairSet);
        dataMap.put(2,unRepairSet);

        return dataMap;
    }

}
